package com.yanqu.road.server.manger.union.unionchange;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.logic.helper.UnionActivityGroupHelper;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.activity.TradeWarActivityMgr;
import com.yanqu.road.server.manger.activity.orewar.OreWarActivityMgr;
import com.yanqu.road.server.manger.rank.YRankMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

public class UnionYRankAction {

    private static Logger logger = LogManager.getLogger(UnionYRankAction.class.getName());

    public static void refreshUnionRank(String unionUid) {
        try {
            List<ActivityInfo> infoList = NormalActivityMgr.getShowTimeActivityInfoList();
            //盐场的要特殊拿出来
            List<ActivityInfo> openActivityInfoList = OreWarActivityMgr.getOpenActivityInfoList();
            infoList.addAll(openActivityInfoList);
            //商会商战的要特殊拿出来
            ActivityInfo openActivityInfo = TradeWarActivityMgr.getOpenActivityInfo();
            if(null != openActivityInfo) {
                infoList.add(openActivityInfo);
            }
            for (ActivityInfo info : infoList) {
                if (!ActivityMgr.activityInTime(info)) {
                    return;
                }
                List<Integer> typeList = new ArrayList<>();

                // 大航海
                if (info.getType() == eActivityType.HangHaiActivity.getValue()) {
                    typeList.add(eGamePlayerEventType.HangHaiUnionMoneyRank.getValue());
                }
                // 商会经验
                if (info.getType() == eActivityType.CrossUnionActivity.getValue()) {
                    typeList.add(eGamePlayerEventType.UnionExpRiseRank.getValue());
                }
                // 海上争霸
                if (info.getType() == eActivityType.SeacraftActivity.getValue()) {
                    typeList.add(eGamePlayerEventType.SeacraftPirateRiotUnionScoreRank.getValue());
                }

                if (info.getType() == eActivityType.LangYaBang.getValue()){
                    typeList.add(eGamePlayerEventType.LangYaUnionScoreRank.getValue());
                }

                if (info.getType() == eActivityType.DaFuWeng.getValue()){
                    typeList.add(eGamePlayerEventType.DaFuWengUnionScoreRank.getValue());
                    typeList.add(eGamePlayerEventType.DaFuWengUnionDamageRank.getValue());
                }

                if (info.getType() == eActivityType.Tomb.getValue()){
                    typeList.add(eGamePlayerEventType.TombUnionRank.getValue());
                }

                if (info.getType() == eActivityType.OreWarActivity.getValue()) {
                    typeList.add(OreWarActivityMgr.CONDITION_TYPE_UNION);
                }


                if (info.getType() == eActivityType.Twins.getValue()){
                    typeList.add(eGamePlayerEventType.TwinsUnionScoreRank.getValue());
                }

                //巅峰海战
                if (info.getType() == eActivityType.PeakSeacraftActivity.getValue()) {
                    typeList.add(eGamePlayerEventType.PeakSeacraftUnionRank.getValue());
                }

                if (info.getType() == eActivityType.PeakStrongHold.getValue()){
                    typeList.add(eGamePlayerEventType.PeakStrongHoldUnionIntegralRank.getValue());
                }

                if (info.getType() == eActivityType.CrossTradeWarActivity.getValue()){
                    typeList.add(eGamePlayerEventType.CrossTradeWarUnionScoreRiseRank.getValue());
                }

                int groupId = GameUnionActivityGroupMgr.getGroupId(info.getActivityId(), unionUid);
                if (groupId == UnionActivityGroupHelper.NO_GROUP_ID) {
                    continue;
                }

                // 上传变化
                for (int type : typeList) {
                    YRankMgr.uploadUnionYRank(info.getActivityId(), String.valueOf(type), unionUid, null);
                }
            }
        } catch (Exception e) {
            logger.error(e);
        }
    }

}
